<template>
	<view class="wrap">
		<view class="wrapItem">
			<view class="wrapItemKey">原密码</view>
			<input class="uni-input" maxlength="6" v-model="passwordOld" password type="text" placeholder="请输入原密码" />
		</view>
		<view class="wrapItem">
			<view class="wrapItemKey">新密码</view>
			<input class="uni-input" maxlength="6" v-model="passwordNew" password type="text" placeholder="请输入新密码" />
		</view>
		<view class="wrapItem">
			<view class="wrapItemKey">确认密码</view>
			<input class="uni-input" maxlength="6" v-model="passwordConfim" password type="text" placeholder="请确认密码" />
		</view>
		<view class="btn" @click="preservation">保存</view>
	</view>
</template>

<script>
	const NET = require('../../utils/request')
	const API = require('../../config/api')
	export default {
		data() {
			return {
				passwordOld: '',
				passwordNew: '',
				passwordConfim: ''
			}
		},
		methods: {
			preservation() {
				if (this.passwordOld && this.passwordNew && this.passwordConfim) {
					if (this.passwordNew == this.passwordConfim) {
						NET.request(API.updatePassword, {
							oldPassword: this.passwordOld,
							newPassword: this.passwordNew
						}, 'GET').then(res => {
							uni.showToast({
								title: '修改成功！',
								icon: 'none'
							})
							uni.switchTab({
								url: '../../pages/tabbar/index/index',
							})
						})
					} else {
						uni.showToast({
							title: '两次输入密码不一致！',
							icon: 'none'
						})
					}
				} else {
					uni.showToast({
						title: '信息填写不完整！',
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 30upx;

		.wrapItem {
			border-bottom: 1px solid #F6F6F6;
			height: 106upx;
			display: flex;
			align-items: center;

			.wrapItemKey {
				font-size: 28upx;
				color: #333;
				margin-right: 40upx;
			}
		}

		.btn {
			width: 702upx;
			height: 88upx;
			text-align: center;
			line-height: 88upx;
			color: #fff;
			font-size: 28upx;
			position: fixed;
			bottom: 80upx;
			left: 24upx;
			background-color: #EFB257;
			border-radius: 100upx;
		}
	}
</style>
